#include "selectticket.h"
#include "ui_selectticket.h"

selectticket::selectticket(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::selectticket)
{
    ui->setupUi(this);
    QDate currentDate = QDate::currentDate();
    ui->dateEdit->setDate(currentDate);
}

selectticket::~selectticket()
{
    delete ui;
}

void selectticket::on_exitButton_clicked()
{
    emit sendsignal();
       this->close();
}

void selectticket::on_selectticketButton_clicked()
{
        QString ostation = ui->lineEdit_ostation->text();
              QString destination = ui->lineEdit_destination->text();
              QDate date = ui->dateEdit->date();
              QString odate = date.toString("yyyy-MM-dd")+"%"; // 将日期转换为字符串，格式可以根据您的需求进行调整
              QSqlQuery query;
                      query.prepare("SELECT * FROM 余票信息表 WHERE 出发站 = :ostation AND 目的站 = :destination and 出发时间 like :odate");
                      query.bindValue(":ostation", ostation);
                      query.bindValue(":destination", destination);
                      query.bindValue(":odate", odate);
                      query.exec();

                      if (query.next()) {
                          this->hide();
                              showticket*s=new showticket(ostation,odate,destination);
                              connect(s,SIGNAL(sendsignal()),this,SLOT(reshow()));//当点击子界面时，调用主界面的reshow()函数
                              s->show();
                      } else {
                          // 没有车票
                          QMessageBox::information(this,"提示","暂无车次");

                      }
}
void selectticket::reshow()
{
    this->show();
}
